package com.example.pet.controller;

import com.hj.pet.api.UserInfoService;
import com.hj.pet.model.ReturnT;
import com.hj.pet.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.hj.pet.constant.Code.SUCCESS;

@RequestMapping("/internal/userInfo")
@RestController
public class UserInfoController {
    @Autowired
    UserInfoService userInfoService;

    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> save(@RequestBody UserInfo userInfo){
        userInfoService.save(userInfo);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "updateById",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> updateById(@RequestBody UserInfo userInfo){
        userInfoService.updateById(userInfo);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "findUserById",method = RequestMethod.GET )
    @ResponseBody
    public ReturnT<UserInfo> findUserById(@RequestParam int userId){
        UserInfo userInfo=userInfoService.findUserById(userId);
        return new ReturnT<>(SUCCESS,userInfo);
    }

    @RequestMapping(value = "findUserByAc",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<UserInfo> findUserByAc(@RequestParam String user_account){
        UserInfo userInfo=userInfoService.findUserByAc(user_account);
        return new ReturnT<>(SUCCESS,userInfo);
    }

    @RequestMapping(value = "findUsersSeller",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<List<UserInfo>> findUsersSeller(@RequestParam boolean is_seller){
        List<UserInfo> userInfos=userInfoService.findUsersSeller(is_seller);
        return new ReturnT<>(SUCCESS,userInfos);
    }

    @RequestMapping(value = "findUsersVip",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<List<UserInfo>> findUsersVip(@RequestParam boolean is_vip){
        List<UserInfo> userInfos = userInfoService.findUsersVip(is_vip);
        return new ReturnT<>(SUCCESS,userInfos);
    }

    @RequestMapping(value = "delUserById",method = RequestMethod.DELETE)
    @ResponseBody
    public ReturnT<?> delUserById(@RequestParam int userId){
        userInfoService.delUserById(userId);
        return new ReturnT<>(SUCCESS,"success");
    }

    @RequestMapping(value = "findUsers",method = RequestMethod.GET)
    @ResponseBody
    public ReturnT<List<UserInfo>> findUsers(@RequestBody UserInfo userInfo){
        List<UserInfo> userInfos = userInfoService.findUsers(userInfo);
        return new ReturnT<>(SUCCESS ,userInfos);
    }

    @RequestMapping(value = "addUserInfo",method = RequestMethod.POST)
    @ResponseBody
    public ReturnT<?> addUserInfo(@RequestBody UserInfo userInfo){
        userInfoService.addUserInfo(userInfo);
        return new ReturnT<>(SUCCESS,"success");
    }
}
